﻿using AuroraPlatform.ViewModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace AuroraPlatform.View.Level5
{
    public class ProductSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get 
            {
                ResourceProvider rs = new ResourceProvider();
                return rs.ProdTypes;
            }
        }

        public void SetValue(LightingModel vm, int value)
        {
            vm.ProdClass = value;
        }

        public int GetValue(LightingModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.ProdClass)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class EmptyResourceProvider
    {
        private static ResItem _empty;

        static EmptyResourceProvider()
        {
            ResItem.Builder builder = new ResItem.Builder();
            builder.SetItemID(0);
            builder.SetItemName("    ");
            _empty = builder.Build();
        }

        public IEnumerable<ResItem> ProdTypes
        {
            get
            {
                List<ResItem> list = new List<ResItem>();
                list.Add(_empty);
                ResourceProvider rp = new ResourceProvider();
                list.AddRange(rp.ProdTypes);
                return list;
            }
        }

        public IEnumerable<ResItem> UseArea
        {
            get
            {
                List<ResItem> list = new List<ResItem>();
                list.Add(_empty);
                ResourceProvider rp = new ResourceProvider();
                list.AddRange(rp.UseArea);
                return list;
            }
        }

        public IEnumerable<ResItem> Orgin
        {
            get
            {
                List<ResItem> list = new List<ResItem>();
                list.Add(_empty);
                ResourceProvider rp = new ResourceProvider();
                list.AddRange(rp.Orgin);
                return list;
            }
        }

        public IEnumerable<ResItem> ImpactType
        {
            get
            {
                List<ResItem> list = new List<ResItem>();
                list.Add(_empty);
                ResourceProvider rp = new ResourceProvider();
                list.AddRange(rp.ImpactType);
                return list;
            }
        }

        public IEnumerable<ResItem> LightingExplain
        {
            get
            {
                List<ResItem> list = new List<ResItem>();
                list.Add(_empty);
                ResourceProvider rp = new ResourceProvider();
                list.AddRange(rp.LightingExplain);
                return list;
            }
        }

        public IEnumerable<ResItem> WorkVoltage
        {
            get
            {
                List<ResItem> list = new List<ResItem>();
                list.Add(_empty);
                ResourceProvider rp = new ResourceProvider();
                list.AddRange(rp.WorkVoltage);
                return list;
            }
        }

        public IEnumerable<ResItem> ControlType
        {
            get
            {
                List<ResItem> list = new List<ResItem>();
                list.Add(_empty);
                ResourceProvider rp = new ResourceProvider();
                list.AddRange(rp.ControlType);
                return list;
            }
        }

        public IEnumerable<ResItem> LightingType
        {
            get
            {
                List<ResItem> list = new List<ResItem>();
                list.Add(_empty);
                ResourceProvider rp = new ResourceProvider();
                list.AddRange(rp.LightingType);
                return list;
            }
        }

        public IEnumerable<ResItem> SetupType
        {
            get
            {
                List<ResItem> list = new List<ResItem>();
                list.Add(_empty);
                ResourceProvider rp = new ResourceProvider();
                list.AddRange(rp.SetupType);
                return list;
            }
        }
    }

    public class AreaSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get
            {
                EmptyResourceProvider rs = new EmptyResourceProvider();
                return rs.UseArea;
            }
        }

        public void SetValue(LightingModel vm, int value)
        {
            vm.ProdPlace = value;
        }

        public int GetValue(LightingModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.ProdPlace)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class OrginSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get
            {
                EmptyResourceProvider rs = new EmptyResourceProvider();
                return rs.Orgin;
            }
        }

        public void SetValue(LightingModel vm, int value)
        {
            vm.ProdOrgin = value;
        }

        public int GetValue(LightingModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.ProdOrgin)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class ImpactSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get
            {
                EmptyResourceProvider rs = new EmptyResourceProvider();
                return rs.ImpactType;
            }
        }

        public void SetValue(LightingModel vm, int value)
        {
            vm.PhyImpact = value;
        }

        public int GetValue(LightingModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.PhyImpact)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class ExplainSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get
            {
                EmptyResourceProvider rs = new EmptyResourceProvider();
                return rs.LightingExplain;
            }
        }

        public void SetValue(LightingModel vm, int value)
        {
            vm.OptExplain = value;
        }

        public int GetValue(LightingModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.OptExplain)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class VoltageSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get
            {
                EmptyResourceProvider rs = new EmptyResourceProvider();
                return rs.WorkVoltage;
            }
        }

        public void SetValue(LightingModel vm, int value)
        {
            vm.EleVoltage = value;
        }

        public int GetValue(LightingModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.EleVoltage)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class ControlTypeSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get
            {
                EmptyResourceProvider rs = new EmptyResourceProvider();
                return rs.ControlType;
            }
        }

        public void SetValue(LightingModel vm, int value)
        {
            vm.EleCtlType = value;
        }

        public int GetValue(LightingModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.EleCtlType)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class AdapterClassSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get
            {
                EmptyResourceProvider rs = new EmptyResourceProvider();
                return rs.LightingType;
            }
        }

        public void SetValue(LightingModel vm, int value)
        {
            vm.AdpClass= value;
        }

        public int GetValue(LightingModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.AdpClass)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class SetupSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get
            {
                EmptyResourceProvider rs = new EmptyResourceProvider();
                return rs.SetupType;
            }
        }

        public void SetValue(LightingModel vm, int value)
        {
            vm.ProjSetup = value;
        }

        public int GetValue(LightingModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.ProjSetup)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }
}
